package org.example.hw;


import java.util.*;
import java.util.stream.Collectors;

/**
 * @author: lynn
 * @Descript: compare 写法
 * @date: 2021/2/27 20:05
 * @version: 1.0
4
apple 1 3
apple 2 3
banana 3 7
orige 2 8
banana 2 7
orige 2 7
apple 4 2
banana 3 6
orige 2 7
-1

 */
public class test23 {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
         List<Fruit> fruitList = new ArrayList<>();
        Boolean flag = true;
        int size = 0;
        while (scanner.hasNext()) {
            if (flag) {
                size = scanner.nextInt();
                flag = false;
                continue;
            }

            String s=scanner.nextLine();
            if (s.equals("-1")){
                break;
            }
            if (s!=null && !s.equals("")){
                String[] fruit = s.split(" ");
                Fruit fruit1=new Fruit();
                fruit1.setFruitName(fruit[0]);
                fruit1.setWorkNo(fruit[1]);
                fruit1.setFruitWeight(fruit[2]);
                fruitList.add(fruit1);
            }
        }
        System.out.println("stream out ================");
        Optional.of(fruitList.stream()
                .sorted(Comparator.comparing(Fruit::getWorkNo))
                .sorted(Comparator.comparing(Fruit::getFruitWeight))
                .sorted(Comparator.comparing(Fruit::getFruitName))
                .collect(Collectors.toList()))
                .ifPresent(v -> {
                    for (int i = 0; i <v.size() ; i++) {
                        System.out.println(v.get(i).getFruitName()+" "
                                +v.get(i).getWorkNo()+" "+v.get(i).getFruitWeight());
                    };
        });
        System.out.println("Collections out ============");
        Collections.sort(fruitList,(o1,o2)-> Integer.valueOf(o1.getWorkNo())-Integer.valueOf(o2.getWorkNo()));
        Collections.sort(fruitList,(o1,o2)-> Integer.valueOf(o1.getFruitWeight())-Integer.valueOf(o2.getFruitWeight()));
        Collections.sort(fruitList,((o1, o2) -> o1.getFruitName().compareTo(o2.getFruitName())));
        for (int i = 0; i <fruitList.size() ; i++) {
            System.out.println(fruitList.get(i).getFruitName()+" "
                    +fruitList.get(i).getWorkNo()+" "+fruitList.get(i).getFruitWeight());
        }

    }


    static  class  Fruit  {
        public String fruitName;
        public String workNo;
        public String fruitWeight;


        public void setFruitName(String fruitName) {
            this.fruitName = fruitName;
        }

        public void setWorkNo(String workNo) {
            this.workNo = workNo;
        }

        public void setFruitWeight(String fruitWeight) {
            this.fruitWeight = fruitWeight;
        }

        public String getFruitName() {
            return fruitName;
        }

        public String getWorkNo() {
            return workNo;
        }

        public String getFruitWeight() {
            return fruitWeight;
        }


    }
}